<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>引出生命周期</title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<h2 :style="{opacity}">开始Vue生命周期</h2>
			<button type="button" @click="opacity=1">透明度设置为1</button>
			<button type="button" @click="stop">点击停止变换</button>
		</div>
		<script type="text/javascript">
			new Vue({
				el:"#root",
				data:{
					opacity: 1,
				},
				methods:{
					stop(){
						// clearInterval(this.timer);
						// 直接销毁，无法再进行操作修改 直接干掉VM 无法再驱动页面
						this.$destroy();
					}
				},
				// Vue 完成模板的解析并把初始真实的DOM元素放入页面后(挂载完毕) 调用mouted
				mounted(){
					console.info('mounted');
					this.timer = setInterval(()=> {
						// console.log('setInterval');
						this.opacity -= 0.01;
						if(this.opacity <= 0) this.opacity = 1
					},20);
				},
				beforeDestroy() {
					console.log('vm消除');
					clearInterval(this.timer);
				}
			})
		</script>
	</body>
</html>
